import { instance } from '../request'

const request = instance

/**
 * 用户退出
 * @returns
 */
export const logoutApi = (): PromiseRes => request.post(`/user/logout`)

/**
 * 获取用户信息
 * @returns
 */
export const getUserInfoApi = (): PromiseRes<UserInfoItf> =>
  request.get(`/user/info`)

/**
 * 修改用户信息
 *
 * @param user 用户信息
 * @return s
 */
export const updateUserInfoApi = (user: {
  nickname: string
  phoneNumber?: string
  email?: string
  signature?: string
}): PromiseRes => request.put(`/user/updateInfo`, user)

/**
 * 获取用户角色详情
 *
 * @return s
 */
export const getUserRolesDetailApi = (): PromiseRes<{
  roleIdList: string[]
  roleNameList: string[]
  rolesList: RoleItf[]
}> => request.get(`/user/getUserRoles`)

/**
 * 获取用户可以访问的页面路由
 * @param systemName 系统名称
 * @returns
 */
export const getUserAccessRoutesApi = (
  systemName: string
): PromiseRes<RouteItf[]> =>
  request.get(`/user/getAccessRoutes?systemName=${systemName}`)

/**
 * 分页条件查询用户信息
 * @param page 分页页码
 * @param size 分页大小
 * @param queryCondition 分页查询用户的一些条件
 * @returns
 */
export const queryPageUserListApi = (
  page: number,
  size: number,
  queryCondition: QueryUserConditionItf
): PromiseRes<QueryUserListItf> =>
  request.post(
    `/user/queryPageUserList?page=${page}&size=${size}`,
    queryCondition
  )

/**
 * 分页简单条件查询用户信息
 * @param page 分页页码
 * @param size 分页大小
 * @param queryCondition 分页查询用户的一些条件
 * @returns
 */
export const queryPageUserByEasyApi = (
  page: number,
  size: number,
  user: {
    account?: string
    nickname?: string
  }
): PromiseRes<QueryUserListItf> =>
  request.post(`/user/queryPageUserByEasy?page=${page}&size=${size}`, user)

/**
 * 批量设置用户状态
 * @param userIds 用户id 列表
 * @param status 状态 0 、1
 * @returns
 */
export const setUserStatusApi = (
  userIds: string[],
  status: 0 | 1
): PromiseRes => request.post(`/user/setUserStatus?status=${status}`, userIds)
